package tolgahan.albayrak.as3.reflection
{
	public class ParameterizedInfo extends MemberInfo
	{
		protected var _parameters:Vector.<ParameterInfo> = new Vector.<ParameterInfo>;
		public function ParameterizedInfo(xml:XML, baseType:Type, memberIndex:uint)
		{
			super(xml, baseType, memberIndex);
			for each(var param:XML in xml.parameter)
			{
				_parameters.push(new ParameterInfo(param, null, param.@index[0]));
			}
		}
		public function get parameters():Vector.<ParameterInfo>
		{
			return _parameters.concat();
		}
		
		public function get parameterLength():uint
		{
			return _parameters.length;
		}
		
		public function getParameter(index:uint):ParameterInfo
		{
			return index < _parameters.length ? _parameters[index] : null;
		}
		
		protected function validate(args:Array):Boolean
		{
			for(var i:int=0;i<args.length && i<_parameters.length;i++)
				if(!_parameters[i].validate(args[i]))
					return false;
			return true;
		}
		
		protected function getParameters(args:Array):Array
		{
			var ary:Array = args.concat();
			while(ary.length < _parameters.length)
			{
				var p:ParameterInfo = _parameters[ary.length];
				if(p.optional)
					break;
				ary.push(null);
			}
			if(ary.length > _parameters.length)
				ary.length = _parameters.length;
			return ary;
		}		
	}
}